﻿
using BBICMS.Application.ViewModels;
using BBICMS.Model.ViewModel.Front;
using BBICMS.Repository;
using System;
using System.Linq;
using System.Web;
using System.Web.Mvc;


namespace BBICMS.WebUI.Controllers
{

    public class HomeController : BaseController
    {
        /// <summary>
        /// 选择语言
        /// </summary>
        /// <param name="culture"></param>
        /// <returns></returns>
        public ActionResult SetCulture(string culture)
        {
            // Validate input
            culture = LanguageHelper.GetImplementedCulture(culture);
            RouteData.Values["culture"] = culture;  // set culture

            return RedirectToAction("Index");

            //// Validate input
            //culture = LanguageHelper.GetImplementedCulture(culture);
            //// Save culture in a cookie
            //HttpCookie cookie = Request.Cookies["_culture"];
            //if (cookie != null)
            //    cookie.Value = culture;   // update cookie value
            //else
            //{
            //    cookie = new HttpCookie("_culture");
            //    cookie.Value = culture;
            //    cookie.Expires = DateTime.Now.AddYears(1);
            //}
            //Response.Cookies.Add(cookie);
            //return RedirectToAction("Index");
        }


        public ActionResult Index()
        {

            FrontHomeVM imv = new FrontHomeVM()
            {
                Works = (from p in _unit.Works.GetAll().Where(w => w.Active && w.Recommend)
                               .OrderByDescending(p => p.AddedDate)
                         select p).Take(8).ToList(),

                Solutions = _unit.Solutions.GetAll().Where(m=>m.Active).OrderByDescending(m=>m.Importance).Take(8).ToList(),
                Clients = _unit.Clients.GetAll().Where(m=>m.Active).OrderByDescending(m => m.Importance).ToList(),
            };
           
            
            return View(imv);
        }

        public ActionResult About()
        {
          //  ViewBag.Message = "Your app description page.";
            AboutVM vm = new AboutVM();

            vm.Article = _unit.Posts.GetAll()
                .Where(a => a.Active).Where(a => a.Recommend)
                .OrderByDescending(p => p.AddedDate).FirstOrDefault();
            return View(vm);
        }

        
    }
}
